package com.mjl.shops.activity;

import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.Window;
import android.widget.EditText;

import com.mjl.shops.R;
import com.mjl.shops.base.BaseActivity;
import com.mjl.shops.utils.CommUtils;
import com.mjl.shops.view.GoodsSortConditionView;
import com.mjl.shops.view.IconTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SearchSucceedActivity extends BaseActivity {

    private String Search_Str;

    @BindView(R.id.goods_sort_view)
    GoodsSortConditionView goodsSortConditionView;

    @BindView(R.id.search_et)
    EditText search_et;

    @BindView(R.id.clear_icon)
    IconTextView clear_icon;

    @Override
    protected void setContentViewBefore() {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
    }

    @Override
    protected int getViews() {
        return R.layout.activity_search_succeed;
    }

    @Override
    protected void setViews() {
        ButterKnife.bind(this);

    }

    @Override
    protected void setDate() {
        Search_Str = getIntent().getStringExtra("SEARCH_STR");
        search_et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                search_et.setSelection(s.length());
            }
        });
        search_et.setText(Search_Str);

        goodsSortConditionView.setSortListener(new GoodsSortConditionView.SortListener() {
            @Override
            public void Way(int sort) {
                switch (sort) {
                    case 1:
                        goodsSortConditionView.setStyle(0);
                        break;
                    case 2:
                        goodsSortConditionView.setStyle(1);
                        break;
                    case 3:
                        goodsSortConditionView.setStyle(2);
                        break;
                    case 4:
                        goodsSortConditionView.setStyle(3);
                        break;
                    default:
                        break;
                }
            }
        });
    }

    @Override
    protected String getStateColor() {
        return CommUtils.color_05000000;
    }

    @Override
    protected int getStetaBackgroundStyle() {
        return 1;
    }

    @OnClick({R.id.clear_icon})
    public void OnClick(View view){
        switch (view.getId()){
            case R.id.clear_icon:
                search_et.setText("");
                break;
        }
    }

    public static void StartIntent(Context contexts, String str) {
        Intent intent = new Intent(contexts, SearchSucceedActivity.class);
        intent.putExtra("SEARCH_STR", str);
        contexts.startActivity(intent);
    }
}
